/**
 * @file bsp_rs485.c
 * @brief RS485封装驱动
 * @author wangh (wanghuan3037@fiberhome.com)
 * @version 1.0
 * @date 2020-10-20
 * @copyright Copyright (c) 2020  烽火通信
 ***************************************************************
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version  <th>Author  <th>Description
 * <tr><td>2020-10-20 <td>1.0      <td>wangh   <td>内容
 * </table>
 */ 
#include "bsp_rs485.h"

/**
 * @brief RS485初始化
 * @param  obj         RS485对象
 * @param  uartId      UART编号
 * @param  wr          RS485读写控制
 * @return int8_t Sucess : BSP_SUCCESS
 */
int8_t Rs485Init( Rs485_t *obj, UartId_t uartId, PinNames wr )
{
    obj->uartId = uartId;
    GpioInit( &obj->RS485_WR, wr, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );

    return BSP_SUCCESS;
}

/**
 * @brief RS485发送
 * @param  obj         RS485对象
 * @param  buffer      发送数据指针
 * @param  size        发送数据长度
 */
void Rs485Send( Rs485_t *obj, uint8_t *buffer, uint16_t size )
{
    UartSend( obj->uartId, buffer, size );
}

/**
 * @brief RS485接收
 * @param  obj         RS485对象
 * @param  buffer      接收缓存
 * @param  size        接收长度
 * @param  blockTime   接收阻塞时间（0：直接轮询，portMAX_DELAY：不超时）
 * @return uint16_t 实际FIFO长度
 */
uint16_t Rs485Recv( Rs485_t *obj, uint8_t *buffer, uint16_t size, uint32_t blockTime )
{
    return UartRecv( obj->uartId, buffer, size, blockTime );
}


/*********** (C) COPYRIGHT 2020 FiberHome *****END OF FILE****/
